package com.ymjspace.controller;

import com.ymjspace.Service.UserService;
import com.ymjspace.util.YMJDateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ymjspace.util.MySqlConectionFactory;

import java.sql.ResultSet;
import java.text.ParseException;
import java.util.Date;

/**
 * Package: com.ymjspace.controller
 * Description：
 * Author: YMJ
 * Date:  2020-07-05 18:43
 */
@Controller
public class Login {
    @Autowired
    MySqlConectionFactory mySqlConectionFactory;

    @Autowired
    UserService userService;

    @Autowired
    YMJDateTimeUtil ymjDateTimeUtil;

    @RequestMapping("/getLogin")
    public String getLogin(){
        return "secret";
    }

    @RequestMapping("/login")
    @ResponseBody
    public String login(String username,String password ){
        String acount = username;
        String pwd = password;
        String sql = "select user_email from pfo_user where user_name = 'yumingjun'";
        ResultSet resultSet = mySqlConectionFactory.getResult(sql);
        System.out.println(resultSet.toString());
        return "login success yes,"+acount+pwd;
    }

    @RequestMapping("/show")
    @ResponseBody
    public String show(@RequestParam("str") String str){
        return str;
    }

    @RequestMapping("/getUser")
    @ResponseBody
    public String getUser(String userName){
        String str = userService.getUser(userName);
        System.out.println(str);
        return str;
    }

    @RequestMapping("/getTime")
    @ResponseBody
    public String getTime() throws ParseException {
        Date date = new Date();
        String dateStr1 = ymjDateTimeUtil.formatDateToStr(date,"yyyy-MM-dd");
        String dateStr2 = ymjDateTimeUtil.formatDateToStr(date,"今天是yyyy年MM月dd日hh时mm分ss秒");
        String dateStr3 = ymjDateTimeUtil.formatDateToStr_YMDHMS1(date);
        String dateStr4 = ymjDateTimeUtil.formatDateToStr_YMDHMS2(date);
        String dateStr5 = ymjDateTimeUtil.formatDateToStr_YMDHMS3(date);
        int status = ymjDateTimeUtil.compareDate(date,new Date());
        Long timeDifference = ymjDateTimeUtil.compareTwoDate(date,new Date());
        Long timeDifferenceSecond = ymjDateTimeUtil.compareTwoDateTimeDifferenceSecond(date,ymjDateTimeUtil.parseDateStrToDate_YMDHMS1("2020-10-10 12:00:00"));
        Long timeDifferenceMinute = ymjDateTimeUtil.compareTwoDateTimeDifferenceMinute(date,ymjDateTimeUtil.parseDateStrToDate_YMDHMS1("2020-10-10 12:00:00"));
        Long timeDifferenceHour = ymjDateTimeUtil.compareTwoDateTimeDifferenceHour(date,ymjDateTimeUtil.parseDateStrToDate_YMDHMS1("2020-10-10 12:00:00"));
        Long timeDifferenceDay = ymjDateTimeUtil.compareTwoDateTimeDifferenceDay(date,ymjDateTimeUtil.parseDateStrToDate_YMDHMS1("2020-10-10 23:00:00"));
        Long timeDifferenceYear = ymjDateTimeUtil.compareTwoDateTimeDifferenceYear(date,ymjDateTimeUtil.parseDateStrToDate_YMDHMS1("2010-10-10 23:00:00"));
        return dateStr1;
    }

}
